<head>
	<title>Aros Index</title>
</head>
<body>
<h1><?php echo $this->pageTitle = 'Aros Index'?></h1>
<h5>Hi, 
<?php echo $session->read('Auth.UnionMember.name') ?>!</h5> <br />
<h5>Chức vụ: <?php $pos_id =  $session->read('Auth.UnionMember.pos_id');
		  foreach($positions as $position){
			if(strcmp($pos_id, $position['Position']['id']) == 0){
				echo $position['Position']['position'];
				break;
			}
		  }	?></h5> <br />
<h5><?php echo $html->link('Logout', array('controller'=>'UnionMembers', 'action'=>'logout'))?></h5>

<table>
	<tr>
		<th>id</th>
		<th>parent_id</th>
		<th>model</th>
		<th>name</th>
		<th>lft</th>
		<th>rght</th>
		<th>Chức năng</th>
	</tr>
	<?php
		foreach($aros as $aro)
		{
	?>
	<tr>
		<td><?php echo $aro['Aro']['id'];?></td>
		<td><?php echo $aro['Aro']['parent_id'];?></td>
		<td><?php echo $aro['Aro']['model'];?></td>
		<td>
		<?php
			if(strcmp($aro['Aro']['model'], 'Position' ) == 0){
				foreach($positions as $position){
					if(strcmp($aro['Aro']['foreign_key'], $position['Position']['id']) == 0)
					{
						echo $position['Position']['position'];
						break;
					}
				}
			} 
			else{
				foreach($members as $member){
					if(strcmp($aro['Aro']['foreign_key'], $member['UnionMember']['id']) == 0)
					{					
						echo $member['UnionMember']['name'];
						break;
					}
				}
			}
		?>
		</td>
		<td><?php echo $aro['Aro']['lft'];?></td>
		<td><?php echo $aro['Aro']['rght'];?></td>
		<td>
			<?php echo $html->link('View', array('controller' => 'Aros',
														   'action' => 'view', $aro['Aro']['id']))?>
			|
			<?php echo $html->link('Add Privilege', array('controller' => 'Aros',
														   'action' => 'select_controller', $aro['Aro']['id']))?>											   
		</td>
	</tr>
	<?php 
		} 
	?>
</table>
</body>